package com.photographysharing.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.photographysharing.dto.LikeDTO;
import com.photographysharing.entity.Likes;
import com.photographysharing.exception.ServiceException;
import com.photographysharing.request.SelectByPaging;
import com.photographysharing.response.DatasResponse;
import com.photographysharing.service.LikesService;
import com.photographysharing.mapper.LikesMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Z
* @description 针对表【likes】的数据库操作Service实现
* @createDate 2024-05-14 21:15:11
*/
@Service
public class LikesServiceImpl extends ServiceImpl<LikesMapper, Likes>
    implements LikesService{
    private LikesMapper mapper;

    public LikesServiceImpl(LikesMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public DatasResponse<LikeDTO> select(SelectByPaging pag) {
        int index = pag.getIndex();
        int size = pag.getSize();
        String name = pag.getSearchName();
        String userId = pag.getSearchValue1();
        try {
            List<LikeDTO> datas = mapper.selectByAll((index-1)*size,size,name,userId);
            int count = mapper.selectCount(name,userId);
            return  new DatasResponse<>(count,datas);
        }catch (Exception e){
            throw new ServiceException("查询异常");
        }
    }
}




